﻿using System.Drawing;
using System.Windows.Forms;
using Auxiliary.VecMath;
using Simple3DRedactor.Domain;

namespace Simple3DRedactor.App
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            var scene = new Scene();

            topView.Scene = scene;
            frontView.Scene = scene;
            leftView.Scene = scene;
            perspectiveView.Scene = scene;
            redactor.Scene = scene;
        }

        private void SelectionChanged(Scene arg1, SceneObject arg2)
        {
            topView.SelectedObject = arg2;
            frontView.SelectedObject = arg2;
            leftView.SelectedObject = arg2;
            perspectiveView.SelectedObject = arg2;
            redactor.SelectedObject = arg2;
        }

        private void SphereToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            redactor.Scene.Add(new Sphere());
        }

        private void BoxToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            redactor.Scene.Add(new Box());
        }

        private void CylinderToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            redactor.Scene.Add(new Cylinder());
        }

        private void LightToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            redactor.Scene.Add(new Light());
        }

        private void RemoveToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            if (topView.SelectedObject != null)
                redactor.Scene.Remove(topView.SelectedObject);
        }

        private void MeshToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            if (openMeshFileDlg.ShowDialog() == DialogResult.OK)
            {
                var mesh = Mesh.LoadFromObjFile(openMeshFileDlg.FileName);
                redactor.Scene.Add(new MeshObject { Mesh = mesh });
            }
        }
    }
}
